package com.xhtranslate.service.ali.controller;

import com.xhtranslate.common.dto.ImageOcrDTO;
import com.xhtranslate.common.vo.ResponseEnum;
import com.xhtranslate.common.vo.ResponseVO;
import com.xhtranslate.service.ali.service.AliOcrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 阿里ocr控制器
 *
 * @author liuxuhuang
 * @date 2022/11/20 16:21:03
 */
@RestController
@Api(value = "阿里OCR请求接口", tags = "阿里OCR请求接口")
@RequestMapping(value = "aliOcr")
@Slf4j
public class AliOcrController {
    @Autowired
    private AliOcrService aliOcrService;

    @PostMapping(value = "ocr")
    @ApiOperation(value = "阿里文字识别")
    public ResponseVO baiduOCR(ImageOcrDTO dto) throws Exception {
        log.info("阿里文字识别：" + dto);
        String ocrImg = aliOcrService.ocrImg(dto.getFile());
        if ("".equals(ocrImg) || StringUtils.isBlank(ocrImg)) {
            return ResponseVO.exception(ResponseEnum.FAIL);
        }
        return ResponseVO.succ(ocrImg);
    }
}
